{{include file="../backend/00_subs/01_start.tpl"}}
<div id="loginbox" class="">
    <div class="grid_x pt12 pl12 pr12">
        <form target="integration_asynchronous"
              action="{{base_url("backend/excution/nothing")}}"
              name="frmlogin"
              onsubmit="submitToLogin();"
              autocomplete="off"
              >
            <div class="pb8">
                <table>
                    <tr>
                        <td>Tên đăng nhập</td>
                        <td>
                            <input type="text" 
                                   disabled="1"
                                   style="background-color: #fff"
                                   value="{{$_SESSION['GAPI']['user']->Name}}"
                                   class="classic-input"/>
                            <input type="text" id="username" name="username" 
                                   value="{{$_SESSION['GAPI']['user']->Email}}"
                                   class="classic-input hidden"/>
                        </td>
                    </tr>
                    <tr>
                        <td>Secret Key</td>
                        <td><input type="password" id="password" name="password" class="classic-input"/></td>
                    </tr>
                    <tr>
                        <td class="tac pt4" style="vertical-align: middle">
                            <a href="{{'OAuth'|@base_url}}">
                            <img src="{{base_url()}}syslib/sysimages/16/google1.png"
                                 title="Đăng nhập bằng tài khoản Google"
                                 />
                            <img src="{{base_url()}}syslib/sysimages/16/gmail.png"
                                 title="Đăng nhập bằng tài khoản Gmail"
                                 />
                            </a>
                        </td>
                        <td class="tal pt4">
                            <button type="submit" class="classic-button">Đăng nhập</button>
                        </td>
                    </tr>
                </table>
                <div class="clear"></div>
<!--                <div id="timeleft" title="Blocked time." class="mt4 pa w100pc l0 b0 hidden" style="background: red">
                    <div class="processbar" style="width: 1%;background: #eee;height: 8px;"></div>
                </div>-->
            </div>
        </form>
        <div class="clear"></div>
    </div>
    
</div>
<script>
    $(document).tooltip({
        track: true,
        position: {
            my: "center top+20",
            at: "center bottom-20"
        }
    });
    login();
    function process(){
        if($("#timeleft").is(':hidden')){
            $("#timeleft .processbar").animate({width:"100%"}, 15*60*1000)
            $("#timeleft").show();
        }
    }
    function login(){
        //ShowConfirmDialogMessage($("#loginbox"),"Đăng Nhập !",login);
        var tit="<img class='pa t7 l8 ico16'src='"+baseurl+"syslib/sysimages/16/login.png'/><font class='pl20'>Đăng Nhập !</font>";
        $("#loginbox").dialog({
            modal: true,
            autoOpen            : true,
            minwidth      :'320px',
            resizable: false,
            width      :'auto',
            title: tit,
            closeOnEscape       : false,
            //hide                : "explode",
            buttons: {
            },
            close: function(event, ui) { 
                if (callback && typeof(callback) === "function") { 
                    try{
                        callback();           
                    }catch(e){

                    }
                } 
            },
            create:function () {
                $(this).closest(".ui-dialog")
                .find(".ui-dialog-titlebar-close") // the first button
                .hide();
            }
        });    
    }
    function submitToLogin(){
        if(!_FcheckFilled($("#username").val())){
            uiMessage("User Name is Invalid, Please try again !");
            return;
        }
        if(!_FcheckFilled($("#password").val())){
            $("#password").focus();return;
        }
        var surl="{{base_url("backend/excution/login")}}";
        var odata={
            username    :   $("#username").val(),
            password    :   $("#password").val()
        };
        myAjax(surl, odata, function( oresult ){
            try{
                if(oresult.result==-999){
                    ShowErrorDialogMessage(oresult.message);
                    //process();
                }else if(oresult.result<0){
                    ShowErrorDialogMessage(oresult.message);
                }else{
                    $("#integration_asynchronous").attr("src","{{base_url("backend/excution/mylocation")}}");
                    ShowNoticeDialogMessage(oresult.message);
                }
            }catch(e){ ShowErrorDialogMessage(e.message); }
        });
    }
</script>
{{include file="../backend/00_subs/04_end.tpl"}}